package com.sdk.widget;


import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.android.sdk.R;
import com.sdk.util.DisplayManager;


public class NavigationGallery extends LinearLayout {
	private int totalCount = 0;
	Bitmap selectedBitmp;
	Bitmap normalBitmap;
	private static final int NAVIGATION_BALL_SIZE = 13;

	public NavigationGallery(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs);
		initContentData();
	}

	public NavigationGallery(Context context, AttributeSet attrs) {
		super(context, attrs);
		initContentData();
	}

	public NavigationGallery(Context context) {
		super(context);
		initContentData();
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	private void initContentData() {
		selectedBitmp = BitmapFactory.decodeResource(getResources(),
				R.drawable.radiobutton_on_background);
		normalBitmap = BitmapFactory.decodeResource(getResources(),
				R.drawable.radiobutton_off_background);
		setOrientation(HORIZONTAL);
		setSelectedPosition(0);
	}

	public void setSelectedPosition(int selectedPostion) {
		removeAllViews();
		LinearLayout.LayoutParams layoutParams = new LayoutParams(
				DisplayManager.dipToPixel(NAVIGATION_BALL_SIZE),
				DisplayManager.dipToPixel(NAVIGATION_BALL_SIZE));
		for (int i = 0; i < totalCount; i++) {
			ImageView imageView = new ImageView(getContext());
			if (i == selectedPostion) {
				imageView.setImageBitmap(selectedBitmp);
			} else {
				imageView.setImageBitmap(normalBitmap);
			}
			addView(imageView, layoutParams);
			invalidate();
		}
	}
}
